function spaces(n) {
    y = "";
    while (n--) {
        y += "&nbsp;";
    }
    return y;
}

function addedItem(commonid) {
    return "<li id='"+commonid+"' class='ssw_sortable_li ssw_sortable_li_disabled' style='border:solid 1px white;background-color:white;'>&nbsp;</li>";
    //return "<a id='"+commonid+"' class='ssw_sortable_add'> "+commonid+spaces(9)+" </a>";
}

function sortListInit(pref,r,c,ops) {
    if (ops == null) {
        ops = [];
    }
    var len = ops.length;
    var commonid = pref+"-"+r+"-"+c;
    y = "<div>";
    y += "<ul id='"+commonid+"' class='ssw_sortable'>";
    for (var s=0; s<len; s++) {
        y += "<li class='ssw_sortable_li'>"+ops[s].text+"</li>";
    }
    y += addedItem(commonid);
    y += "</ul>";
    y += "</div>";
    return y;
}

days = null;
function nameOfDay(c) {
    if (days == null) {
        days = {0:'Mon', 1:'Tue', 2:'Wed', 3:'Thu', 4:'Fri'};
    }
    return days[c];
}

slots = null;
function times(r){
    if (slots == null) {
        slots = {0:'4-5', 1:'5-6', 2:'6-7', 3:'7-8'};
    }
    return slots[r];
}

function title0() {
    return "";
}

function tableInit(pref, cols, rows, ops, target, titlet, titler, titlec) {
    var y = "<div><p><table>";
    y += "<tr><td colspan="+(cols+1)+">"+titlet+"</td></tr>";
    y += "<tr><td></td>";
    for (var c=0; c<cols; c++) {
        y += "<td>"+titlec(c)+"</td>";
    }    
    y += "</tr>"; 
    for (var r=0; r<rows; r++) {
        y += "<tr>";
        y += "<td>"+titler(r)+"</td>";
        for (var c=0; c<cols; c++) {
            y += "<td class='ssw_sortable_td'>";
            
            y += sortListInit(pref,r,c,ops);
            
            y += "</td>";
        }
        y += "</tr>";//<tr><td> &nbsp;</td></tr>";
    }
    y += "<table></p></div>";
    
    $(target).html(y);
}

function app1() {
    $(".ssw_sortable").sortable({
        connectWith:".ssw_sortable",
        items: "li:not(.ssw_sortable_li_disabled)",
        start:function(event, ui) {
            var listObject = ui.item.context.parentElement;
            var count = listObject.childElementCount;
            var commonid = listObject.id;
            if (count <= 2) {
                $("ul#"+commonid+".ssw_sortable").append(addedItem(commonid));
            }
        },
        over:function(event, ui) {
            var listObject = ui.item.context.parentElement;
            var count = listObject.childElementCount;
            var commonid = listObject.id;
            var x = 0;
        },
        stop:function(event, ui) {
            var listObject = ui.item.context.parentElement;
            var count = listObject.childElementCount;
            var commonid = listObject.id;
            $("li#"+commonid+".ssw_sortable_li").remove();
            
            if (count <= 1) {
                $("ul#"+commonid+".ssw_sortable").append(addedItem(commonid));
            }
        }
    }).disableSelection();
}

function publish(from,to) {
    from = "#" + from;
    to = "#" + to;
    //var dddd = document.body.innerHTML;
    var xxxx = $(from).html();
    $(to).html(xxxx);
    $(from).html('');
}

function retrieveOps() {
    var ops = [];
    for (var i=0; i < 22; i++) {
    }
    ops.push({text:"Murmaids, U12 Girls, Borsoni"});
    ops.push({text:"Seagulls, U14 Boys, Chiodo"});
    ops.push({text:"Roadrunners, U15 Boys, Hayton"});
    ops.push({text:"Lions"});
    ops.push({text:"Penguins"});
    ops.push({text:"Tigers 1/3"});
    ops.push({text:"Tigers 2/3"});
    ops.push({text:"Tigers 3/3"});
    ops.push({text:"Bears"});
    ops.push({text:"Unicorns"});
    ops.push({text:"Horses"});
    ops.push({text:"Gorillas"});
    ops.push({text:"Whales"});
    ops.push({text:"Dolphins"});
    return ops;
}
  
